package com.aizuda.boot.modules.common.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 交易方类型枚举
 */
@Getter
@AllArgsConstructor
public enum CounterpartyTypeEnum {
    CUSTOMER(1, "客户"),
    SUPPLIER(2, "供应商");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     * 
     * @param code 代码
     * @return 枚举对象
     */
    public static CounterpartyTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (CounterpartyTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据名称获取枚举
     * 
     * @param desc 描述
     * @return 枚举对象
     */
    public static CounterpartyTypeEnum getByDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (CounterpartyTypeEnum type : values()) {
            if (type.getDesc().equals(desc)) {
                return type;
            }
        }
        return null;
    }
} 